package com.ruipengkj.service.impl;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.ruipengkj.bean.TCommodityPicture;
import com.ruipengkj.commons.base.query.BaseQuery;
import com.ruipengkj.commons.base.query.PageModel;
import com.ruipengkj.dao.TCommodityPictureDao;
import com.ruipengkj.service.TCommodityPictureService;
@Service
public class TCommodityPictureServiceImpl implements TCommodityPictureService {

	@Resource
	private TCommodityPictureDao TCommodityPictureDao;//DAO层
	
	//根据条件查询
	@Override
	public List<TCommodityPicture> findService(TCommodityPicture entity) throws Exception {
		String hql = "select o from TCommodityPicture o";
		StringBuffer whereHQL = new StringBuffer();
		List<Object> param = new ArrayList<Object>();
		if (entity != null) {
			if(entity.getTCommodity()!=null&&entity.getTCommodity().getCommodityID() != null){
				whereHQL.append("o.TCommodity=?").append(BaseQuery.AND);
				param.add(entity.getTCommodity());
			}
			if(whereHQL.length()>4)
				whereHQL.delete(whereHQL.length()-5, whereHQL.length());
		}
		LinkedHashMap<String, String> orderby = new LinkedHashMap<String, String>();
		return TCommodityPictureDao.findDao(hql, whereHQL.toString(), param, orderby);
	}
		
	
	//根据ID翻页查询
	@Override
	public PageModel<TCommodityPicture> getScrollService(int firstResult,
			int maxResult, TCommodityPicture entity) throws Exception {
		String hql = "select o from TCommodityPicture o";
		StringBuffer whereHQL = new StringBuffer();
		List<Object> param = new ArrayList<Object>();
		if (entity != null) {
			if(whereHQL.length()>4)
				whereHQL.delete(whereHQL.length()-5, whereHQL.length());
		}
		LinkedHashMap<String, String> orderby = new LinkedHashMap<String, String>();
		return TCommodityPictureDao.getScrollDao(hql, whereHQL.toString(), param, firstResult, maxResult, orderby);
	}

	//修改
	@Override
	public void modifyService(TCommodityPicture entity) throws Exception {
		TCommodityPictureDao.modifyDao(entity);
		
	}
	//添加
	@Override
	public void saveService(TCommodityPicture entity) throws Exception {
		TCommodityPictureDao.saveDao(entity);
	}

	//根据ID删除
	@Override
	public void deleteService(String id) throws Exception {
		TCommodityPictureDao.deleteDao(id);
		
	}
	//根据ID查询
	@Override
	public TCommodityPicture getByIdService(String id) throws Exception {
		return TCommodityPictureDao.getByIdDao(id);
	}
	//添加或修改
	@Override
	public void saveOrUpdateService(TCommodityPicture entity) throws Exception {
		TCommodityPictureDao.saveOrUpdateDao(entity);
	}
	//添加返回ID
	@Override
	public Serializable saveRetService(TCommodityPicture entity) throws Exception {
		return TCommodityPictureDao.saveRetDao(entity);
	}

	public TCommodityPictureDao getTCommodityPictureDao() {
		return TCommodityPictureDao;
	}


	public void setTCommodityPictureDao(TCommodityPictureDao tCommodityPictureDao) {
		TCommodityPictureDao = tCommodityPictureDao;
	}
	
}
